package cn.legend.travel.admin.destination.dao.persist.repository.impl;

import cn.legend.travel.admin.destination.dao.persist.mapper.SceneryDetailMapper;
import cn.legend.travel.admin.destination.dao.persist.repository.ISceneryDetailRepository;
import cn.legend.travel.admin.destination.pojo.entity.SceneryDetail;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Repository;

@Repository
@RequiredArgsConstructor
public class SceneryDetailRepositoryImpl implements ISceneryDetailRepository {
    private final SceneryDetailMapper mapper;

    @Override
    public int update(Long id, String content) {
        SceneryDetail detail = new SceneryDetail();
        detail.setContent(content);
        QueryWrapper<SceneryDetail> wrapper = new QueryWrapper<>();
        wrapper.eq("scenery_id", id);
        return mapper.update(detail, wrapper);
    }

    @Override
    public int deleteByScenery(Long id) {
        QueryWrapper<SceneryDetail> wrapper = new QueryWrapper<>();
        wrapper.eq("scenery_id", id);
        return mapper.delete(wrapper);
    }

    @Override
    public int addNew(Long id, String content) {
        SceneryDetail detail = new SceneryDetail();
        detail.setSceneryId(id);
        detail.setContent(content);
        return mapper.insert(detail);
    }
}
